<template>
  <div style="background-color: #EAEAEA;">
  	<div class="tab-h" >
      <div class="tab-item" v-bind:class="[num == index ?'active' : '']" v-for="(item,index) in tabs" :key="index" @click="tab(index)">{{item}}</div>
    </div>
    <PayTran v-if="num == 0"></PayTran>
    <RechargeTran v-if="num == 1"></RechargeTran>
  </div>
</template>

<script>
import api from '@/utils/api'
import { mapState, mapActions ,mapGetters } from 'vuex'
import PayTran from "@/components/pay_tran"
import RechargeTran from "@/components/recharge_tran"
export default {
  components: {
    PayTran,
    RechargeTran
  },
  data () {
    return {
      tabs: ["消费记录", "充值记录"],
      num:0,
    }
  },
  computed: {
    ...mapGetters([
      'user',
    ])
  },
  beforeMount() {
    console.log('beforeMount')
    if (!this.user || !this.user.id) {
      // 用户未授权
      let url = 'get_user_info?callback_url=transaction_record'
      wx.redirectTo({
        url: url
      })
      return
    }
  },
  methods: {
    tab(index) {
      this.num = index;
    },
  },
  mounted () {
    this.num = 0
  }
}
</script>

<style >
.tab-h{
  width: 100%;
  display: flex;
  flex-direction:row;
  line-height: 40px;
  height:40px;
  font-size: 20px;
  background: white;
}
.tab-item{
  width: 50%;
  display: inline-block;
  text-align: center;
}
.tab-item.active{
  position: relative;
}
.tab-item.active:after{
  content: "";
  display: block;
  height: 4px;
  width: 80px;
  background: #4F4F4F;
  position: absolute;
  bottom: 0;
  left:50%;
  transform: translate(-50%);
  border-radius: 1px;
}
</style>
